package com.manager.controller;

import com.common.result.FileResult;
import com.manager.service.fileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Controller
@RequestMapping("/fileUpload")
public class fileUploadController {

    @Autowired
    private com.manager.service.fileUploadService fileUploadService;
    @RequestMapping("/save")
    public FileResult upload(MultipartFile file) throws IOException {
        String fileName=file.getOriginalFilename();
        String date= DateTimeFormatter.ofPattern("YYYY-MM-DD")+fileName.substring(fileName.lastIndexOf("."));
        fileName=date+fileName;
        return fileUploadService.fileUpload(file.getInputStream(),fileName);
    }
}
